import 'babel-polyfill'
import promise from 'es6-promise'
promise.polyfill()
import Vue from 'vue'

import 'normalize.css/normalize.css'// A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import router from './router'
import store from './store'

import '@/icons' // icon
import '@/permission' // permission control

// Vue.use(ElementUI, { locale })
Vue.use(ElementUI)

// 自定义element-ui Message组件
import { DonMessage } from '@/utils/DonMessage'
Vue.prototype.$message = new DonMessage()

import * as filters from './filters' // global filters

// 注册全局实用过滤器
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

//权限指令
Vue.directive('handle-auth', {
  //1-被绑定
  bind: function(el, binding) {
  },
  // 2-被插入
  inserted: function(el, binding) {
    const arg = binding.arg
    const { handleAuth } = binding.value.meta

    if (!handleAuth) {
      el.parentNode.removeChild(el)
      return
    }

    if (!!handleAuth && !(arg && handleAuth[arg])) {
      el.parentNode.removeChild(el)
    }
  },
  //3-更新
  update: function(el, binding) {
  },
  //4-更新完成
  componentUpdated: function(el, binding) {
  },
  //5-解绑
  unbind: function(el, binding) {
  }
})

// 设置为 false 以阻止 vue 在启动时生成生产提示
Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
